package com.lz.football.module.sign.view
{
	import com.common.stdlib.DateUtil;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.base.IComponent;
	import com.lz.football.module.sign.item.LoginSignItem;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;

	/**
	 *日历面板 
	 * @author lake
	 * 
	 */	
	public class CalendarPanel extends Sprite implements IComponent
	{
		/**
		 *skin 
		 */		
		private var _symbolSkin :MovieClip;
		/**
		 *天数容器 
		 */		
		private var dayContainer			:MovieClip;
		/**
		 * 连续签到
		 */		
		//private var txtSignDay			 	:TextField;
		/**
		 * 月签到
		 */		
		private var txtMonthSignDay 		:TextField;
		/**
		 * 时间 -- 年月
		 */		
		private var txtDate		 		:TextField;
		/**
		 *天数item 数据 
		 */		
		private var dayItems				:Array = [];
		/**
		 *数据 
		 */		
		private var _data :*;
		
		public function CalendarPanel()
		{
			super();
		}
		/**
		 * 设置数据
		 * @param value
		 * 
		 */		
		public function set data(value:*):void
		{
			_data = value;
			setCalendarView();
		}
		/**
		 *设置日历显示 
		 * 
		 */		
		private function setCalendarView():void
		{
			//txtSignDay.htmlText = _data.continue_sign + "天";
			txtMonthSignDay.htmlText = _data.sign_days + "天";
			var signDayTags :Array = _data.signDayTags;
			var i :int;
			var signItem :LoginSignItem;
			for(i = 0;i < signDayTags.length;i++)
			{
				signItem = dayItems[i];
				if(signDayTags[i])
				{
					signItem.bg.visible = true;
				}
				else
				{
					signItem.bg.visible = false;
				}
			}
		}
		/**
		 * 获取数据
		 * @return 
		 * 
		 */		
		public function get data():*
		{
			return _data;
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = view as MovieClip;
			//txtSignDay=  _symbolSkin.txtSignDay;
			txtMonthSignDay=  _symbolSkin.txtMonthSignDay;
			txtDate=  _symbolSkin.txtDate;
			dayContainer = _symbolSkin.dayContainer;
			var timeMills :Number = AppData.getInstance().time * 1000;
			var curDate :Date = new Date(timeMills);
			var monthStr :String = (curDate.month + 1)<10?("0" + (curDate.month + 1)):((curDate.month + 1) + "");
			txtDate.htmlText = curDate.fullYear + "年" + monthStr + "月";
			//计算日历
			var year 	:int = curDate.fullYear;
			var month 	:int = curDate.month;
			var date	:int = 1;
			var firstDate :Date = new Date(year,month,date);//本月第一天
			var day 	:int = firstDate.day;//第一天是星期几
			var monthDays :int = DateUtil.greMonthManyDays(year,month + 1); 
			var i :int = 0;
			var signItem :LoginSignItem;
			for(i = 0;i < monthDays;i++)
			{
				signItem = new LoginSignItem();
				signItem.initUI();
				signItem.txtDay.htmlText = "" + (i + 1);
				dayItems.push(signItem);
			}
			var row :int;
			var col :int;
			i = 0;
			dayContainer.y += 5;
			dayContainer.x += 0;
			for(row = 0;row < 6;row ++)
			{
				for(col = day;col < 7;col ++)
				{
					if(i < dayItems.length)
					{
						signItem = dayItems[i];
						signItem.x = col * (39 - col * .4);
						signItem.y = row * (30 - row * .2);
						dayContainer.addChild(signItem);
						i++;
					}
				}
				day = 0;
			}
			addEvtListener();
		}
		/**
		 *数据更新 
		 * 
		 */		
		public function updateData():void
		{
			setCalendarView();
		}
		/**
		 * 添加事件
		 * 
		 */		
		public function addEvtListener():void
		{
			
		}
		/**
		 * 
		 * 删除事件
		 */		
		public function removeEvtListener():void
		{
			
		}
		/**
		 * 销毁
		 * 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
		}
	}
}